package cn.tedu.cn.tedu.collection2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TestList {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();

        list.add("大力娃");
        list.add("千顺娃");
        list.add("头铁娃");
        list.add("喷火娃");
        list.add("喷水娃");
        list.add("隐身娃");
        list.add("小紫娃");
        System.out.println(list);
//        list.clear();
//        System.out.println(list);
        System.out.println(list.contains("喷火娃"));
        System.out.println(list.equals("喷水娃"));
        System.out.println(list.isEmpty());
        System.out.println(list.remove("隐身娃"));
        System.out.println(list.size());
        System.out.println(Arrays.toString(list.toArray()));
/*list集合是有序的,可以根据索引来操作集合中的元素
* 可以存放重复的数据*/
        list.add("小蝴蝶");
        list.add("小蝴蝶");
        list.add(1,"蛇精");
        list.add(0,"爷爷");

        System.out.println(list);

        System.out.println(list.indexOf("小蝴蝶"));
        System.out.println(list.lastIndexOf("小蝴蝶"));
        System.out.println(list);
        list.remove(5);//根据下标删除元素
        System.out.println(list);
        System.out.println(list.get(5));
        System.out.println(list.set(8,"喷火娃"));
        System.out.println(list);


        List<String> list2=new ArrayList<>();
        list2.add("1");
        list2.add("2");
        list2.add("3");
        list2.add("4");
        System.out.println(list2);
        list.addAll(list2);
        System.out.println(list);
        list.addAll(1,list2);
        System.out.println(list);




    }
}
